class Solution {
    public boolean isequal(String p,int[]a,int[]b){
        for(int i=0;i<p.length();i++){
            if(a[p.charAt(i)]!=b[p.charAt(i)])
               return false;
        }
        return true;
    }
    public List<Integer> findAnagrams(String s, String p) {
        List<Integer> ret=new ArrayList<Integer>();
        int left=0,right=0,count=0;
        int []S_hash=new int[128];
        int []P_hash=new int[128];
        for(int i=0;i<p.length();i++){
            P_hash[p.charAt(i)]++;
        }
        while(right<s.length()){
            S_hash[s.charAt(right)]++;
            count=right-left+1;
            if(count==p.length()){
                if(isequal(p,P_hash,S_hash)) ret.add(left);
                S_hash[s.charAt(left++)]--;
            }
            right++;
        }
        return ret;
    }
}